<template>
<div>
    
    <el-select v-model="formData.proId" placeholder="请选择贷款产品">
        <el-option
        :label="product.name"
        :value="product.id"
        v-for="product in products"
        :key="product.id"
        >{{ product.name }}</el-option
        >
    </el-select>

    <el-select
        v-model="formData.customerId"
        @change="showMortgages"
        placeholder="请选择客户"
        >
        <el-option
            :label="customer.user.name"
            :value="customer.id"
            v-for="customer in customers"
            :key="customer.id">
            {{ customer.user.name }}
        </el-option>
    </el-select>

    <el-select
        v-model="formData.status"
        @change="showMortgages"
        placeholder="请选择状态"
        >
         <el-option label="待审核" value="1" >
          待审核
        </el-option>
        <el-option label="同意" value="2" >
          同意  
        </el-option>
        <el-option label="拒绝" value="3" >
        拒绝 
        </el-option>
    </el-select>

    <el-button size="mini"  type="primary" @click="serach">搜索</el-button>

  <el-table
    :data="applications"
    style="width: 100%"
    border
    >
     <el-table-column
      prop="customer.user.name"
      label="客户"
      align='center'
      >
    </el-table-column>

     <el-table-column
      prop="product.name"
      label="产品"
      align='center'
      >
    </el-table-column>

     <el-table-column
      prop="money"
      label="金额"
      align='center'
      >
    </el-table-column>

    <el-table-column
      label="日期"
      align='center'
      prop="applyTime">
     
    </el-table-column>

     <el-table-column
      prop="acceptAccount"
      label="收款账号"
      align='center'
      >
    </el-table-column>

    <el-table-column label="操作" align='center'>
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">查看</el-button>

          <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>

  </el-table>

    <el-dialog title="申请信息" :visible.sync="dialogTableVisible" v-if="application!=''">
        <el-descriptions title="客户信息"   >
            <el-descriptions-item label="客户姓名" >{{application.customer.user.name}}</el-descriptions-item>
            <el-descriptions-item label="客户性别">{{application.customer.user.gender}}</el-descriptions-item>
            <el-descriptions-item label="客户年龄">{{application.customer.user.age}}</el-descriptions-item>
            <el-descriptions-item label="居住地">{{application.customer.user.address}}</el-descriptions-item>
            <el-descriptions-item label="客户等级">{{application.customer.level}}</el-descriptions-item> 
            <el-descriptions-item label="业务员">{{application.customer.emp.name}}</el-descriptions-item> 
            <el-descriptions-item label="备注">
            <el-tag size="small">{{application.customer.level=='A'?'优质客户':'普通客户'}}</el-tag>
            </el-descriptions-item>
        </el-descriptions>

        <el-descriptions title="产品信息">
            <el-descriptions-item label="产品名称">{{application.product.name}}</el-descriptions-item>
            <el-descriptions-item label="最大金额">{{application.product.maxMoney}}</el-descriptions-item>
            <el-descriptions-item label="年利率">{{application.product.rate*100+'%'}}</el-descriptions-item>
        </el-descriptions>

        <el-descriptions title="抵押资产" direction="vertical" :column="3" border>
            <el-descriptions-item v-for="(mor,index) in application.mortgageList" :key="mor.id" :label="index+1+':'+mor.name">
                <el-descriptions :column="1" >
                    <el-descriptions-item label="资产估值">{{mor.valuation}}</el-descriptions-item>
                    <el-descriptions-item label="评估公司">{{mor.company.name}}</el-descriptions-item>
                </el-descriptions>
            </el-descriptions-item>
        </el-descriptions>
    
        <el-descriptions title="申请信息" :column="1">
            <el-descriptions-item label="贷款金额">{{application.money}}</el-descriptions-item>
            <el-descriptions-item label="收款账号">{{application.acceptAccount}}</el-descriptions-item>
            <el-descriptions-item label="申请时间">{{application.applyTime}}</el-descriptions-item>
            
        </el-descriptions>
        
        <el-descriptions title="操作记录" :column="2">
          <el-descriptions-item v-for="(pro,index) in  application.processList" :key="pro.id" :label="index+1">
                <el-descriptions :column="1" >
                    <el-descriptions-item label="操作时间">{{pro.time}}</el-descriptions-item>
                    <el-descriptions-item label="留言">{{pro.result}}</el-descriptions-item>
                </el-descriptions>
            </el-descriptions-item>
           <!--  <el-descriptions-item v-for="(pro,index) in  application.processList" :key="pro.id" :label="index+1">{{pro.handle.name}}</el-descriptions-item> 
            <el-descriptions-item v-for="(pro) in  application.processList" :key="pro.id" label="操作时间">{{pro.time}}</el-descriptions-item> 
            <el-descriptions-item v-for="(pro) in  application.processList" :key="pro.id" label="留言">{{pro.result}}</el-descriptions-item>  -->
        </el-descriptions>
        

       
        
       
    </el-dialog>
</div>

</template>

<script>
import global from '@/global.js';
  export default {
    created() {
        /**
         * 获取所有未审核申请表
        */
        this.$axios.post(global.server + '/api/app/condition',{}
        ).then(response => {
                let result = response.data;
                if (result.code == 200) {
                    this.applications = result.data;
                    console.log("applications---->",this.applications);
                }
            });

    this.$axios.post(global.server + "/api/product/getAll").then((response) => {
      console.log("产品信息", response.data.data);
      let result = response.data;
      if (result.code == 200) {
        console.log("产品信息", result.data);
        this.products = result.data;
      }
    });

    /*
     *获取客户列表
     */
    this.$axios
      .post(global.server + "/api/customer/condition")
      .then((response) => {
        let result = response.data;
        if (result.code == 200) {
          this.customers = result.data;
          console.log("customer---->");
          console.log(this.customers);
        }
      });

    },
    data() {
      return {
        products:[],
        applications:[],
        
        dialogTableVisible: false,
        application:'',
        result:'',
        formData:{
            proId:'',
            customerId:'',
            status:''
        },
      }
    },
    methods: {
    /**
     * 编辑
     */
      handleEdit(index, row) {
        console.log(index, row);
        this.dialogTableVisible = true;
        this.application=row;
      },
      /**
       * 审核
       */
      handleExamine(index, row) {
        console.log(index, row);
        this.dialogTableVisible = true;
        this.application = row;
      },

      handleDelete(index, row) {
          console.log(index, row);
         // 二次确认删除
            this.$confirm('确定要删除吗？', '提示', {
                type: 'warning'
            })
                .then(() => {
                    this.$message.success('删除成功');
                    this.del(row);
                    // this.applications.splice(index, 1);
                })
                .catch(() => {});  
    },

    /**
     * 审核结果
     */
        examine(resultID){
            /**
             * 更新申请表和操作记录
             */
            this.$axios.post(global.server + '/api/app/examine',
            {
                "appId":this.application.id,
                "status":resultID,
                'result':this.result
            }).then(response => {
                let result = response.data;
                if (result.code == 200) {
                    this.$alert(resultID==2?"审核通过!":"审核拒绝");
                    this.dialogTableVisible = false;
                    //更新未审核的列表
                    this.del(this.application);

                    this.application='';

                }
            });
        },
        /**
         * 删除已审核的申请信息
         */
        del:function(application){
            //表示先获取这个元素的下标，然后从这个下标开始计算，删除长度为1的元素
            this.applications.splice(this.applications.indexOf(application),1);
        },

        serach(){
        console.log("formData---->",this.formData);
        this.$axios.post(global.server + '/api/app/condition',this.formData)
        .then(response => {
                let result = response.data;
                if (result.code == 200) {
                    this.applications = result.data;
                    
                }
            });
        }
    }
  }
</script>
<style scoped>

    .aaa{
      width: 300px;
    }
    
</style>